package com.hongyun.tms.infra;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * 如果yml中的附件目录不存在，则创建它；若存在，则什么都不做
 *
 * @author peng.li
 * @date 2024-09-03
 */
@Component
public class FileUploadDirectoryInitializer implements CommandLineRunner {

    @Value("${file.upload-dir}")
    private String fileUploadDir;

    @Override
    public void run(String... args) throws Exception {
        Path uploadPath = Paths.get(fileUploadDir);
        if (!Files.exists(uploadPath)) {
            Files.createDirectories(uploadPath);
        }
    }
}